<?php

/**
 * P28n, Persistent Internationalization Component
 *
 * http://bakery.cakephp.org/articles/p0windah/2007/09/12/p28n-the-top-to-bottom-persistent-internationalization-tutorial
 */
class P28nComponent extends Object {
	var $components = array('Session', 'Cookie');

	function startup() {
		if (isset($this->params['lang'])) {
			$this->change($this->params['lang']);
		}
		if (!$this->Session->check('Config.language') && $this->Cookie->read('lang')) {
			$this->change($this->Cookie->read('lang'));
		}
	}

	function change($lang = null) {
		if (!empty($lang)) {
			$this->Session->write('Config.language', $lang);
			$this->Cookie->write('lang', $lang, null, '+350 day');
		}
	}
}
?>
